''' Assignment: Functions, parameters & local variables Part 2 - Activity #2 Mission 4 Display with one function for all buttons ''' from codex import * from time import sleep messages = ["Press Up", "Press Down", "Press Left", "Press Right"] btns = [BTN_U, BTN_D, BTN_L, BTN_R] # One function for game play def play_game(choice): if choice == "easy": delay = 1.5 else: delay = 0.75 for count in range(len(messages)): message = messages[count] button = btns[count] display.show(message) sleep(delay) pressed = buttons.is_pressed(button) if pressed: pixels.set(count, GREEN) else: pixels.set(count, RED) def intro(): display.print("Welcome to") display.print("my buttons game") display.print() display.print("Press the button") display.print("before time runs") display.print("out") display.print("Press A to begin") def wait(): while True: if buttons.was_pressed(BTN_A): break def instructions(): display.clear() display.print("Do you want") display.print("easy or hard?") display.print("Press A for easy") display.print("Press B for hard") while True: if buttons.was_pressed(BTN_A): choice = "easy" break if buttons.was_pressed(BTN_B): choice = "hard" break return choice def ending(): display.clear() display.print("Game Over") display.print("Thank you") def play_again(): global continues display.clear() display.print("Play again?") display.print("A = Yes") display.print("B = No") while True: if buttons.was_pressed(BTN_A): pixels.set([BLACK, BLACK, BLACK, BLACK]) break if buttons.was_pressed(BTN_B): continues = False break # Main Program intro() wait() continues = True while continues: choice = instructions() play_game(choice) play_again() ending()